package com.briup.ptp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.briup.ptp.entity.Disease;

import com.briup.ptp.mapper.IllnessMapper;

import com.briup.ptp.service.IllnessService;

import com.briup.ptp.utils.PTPException;
import com.briup.ptp.utils.ResultCode;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname IllnessServiceImpl
 * @Description TODO
 * @Date 2024/2/25 15:18
 * @Created by ASUS
 * @Version v1.0.0
 */
@Service
public class IllnessServiceImpl extends ServiceImpl<IllnessMapper, Disease> implements IllnessService {

    @Autowired
    private IllnessMapper mapper;

    @Override
    public PageInfo<Disease> findIllness(String name, Integer PageSize, Integer pageNum) {
        PageHelper.startPage(pageNum,PageSize);
        List<Disease> list = mapper.findIllness(name);
        PageInfo<Disease> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public void saveOrUpdateIllness(Disease disease) {
        if(disease.getId()==null){
            mapper.saveI(disease);
        }else {
            mapper.updateI(disease);
        }
    }

    @Override
    public void updateIllness(Integer id) {
       Disease disease = mapper.findByIdDisease(id);
        if (disease==null) {
            throw new PTPException(ResultCode.DATA_NONE);
        }
        mapper.updateI(disease);

    }

    @Override
    public void deleteDisease(Integer id) {
        mapper.deleteDisease(id);
    }

    @Override
    public void batchDeleteDisease(List<Integer> id) {
        mapper.batchDeleteDisease(id);
    }


}

